package hoowin.app.wsnd.service;

import hoowin.app.wsnd.dao.ITranslationDao;
import hoowin.app.wsnd.dao.IUpdownDao;
import hoowin.app.wsnd.model.Translation;
import hoowin.basic.service.UserPool;

import java.util.Iterator;
import java.util.List;

public class TranslationService {
	private ITranslationDao translationDao;
	private UserPool up;
	private IUpdownDao updownDao;
	public List<Translation> getTranslationListByStatusId(int statusId){
		List<Translation> translations = translationDao.getTranslationListByStatusId(statusId);
		Iterator<Translation> it = translations.iterator();
		while(it.hasNext()){
			detailizeTranslation(it.next());
		}
		return translations;
	}
	private void detailizeTranslation(Translation translation){
		translation.setPublisher(up.getUserById(translation.getPublisherId()));
		translation.setUpdowns(updownDao.getUpdownListByTranslationId(translation.getId()));
	}
	public boolean addTranslation(String content, String language, int statusId, int publisherId){
		if(statusId==0 || publisherId==0)return false;
		Translation translation = new Translation();
		translation.setContent(content);
		translation.setLanguage(language);
		translation.setPublisherId(publisherId);
		translation.setStatusId(statusId);
		return translationDao.addTranslation(translation)>0;
	}
	public void setTranslationDao(ITranslationDao translationDao) {
		this.translationDao = translationDao;
	}
	public ITranslationDao getTranslationDao() {
		return translationDao;
	}
	public void setUp(UserPool up) {
		this.up = up;
	}
	public UserPool getUp() {
		return up;
	}
	public void setUpdownDao(IUpdownDao updownDao) {
		this.updownDao = updownDao;
	}
	public IUpdownDao getUpdownDao() {
		return updownDao;
	}
}
